#define _CRT_SECURE_NO_WARNINGS 1
typedef struct ListNode LN;

struct ListNode* removeElements(struct ListNode* head, int val) {
    if (head == NULL)
        return NULL;
    LN* cur = head;
    LN* newhead, * tail;
    newhead = tail = (LN*)malloc(sizeof(LN));
    while (cur)
    {
        if (cur->val != val)
        {
            tail->next = cur;
            tail = cur;
        }
        cur = cur->next;
    }
    tail->next = NULL;
    return newhead->next;
}